@extends('layouts.app')

@section('title', translate('收货地址'))
@section('content')
@include('common.header', ['title'=> translate('收货地址')])
<link rel="stylesheet" href="/fontpage/css/cart_check.css">
<link rel="stylesheet" href="/fontpage/css/animate.css">
<script src="/fontpage/js/iscroll.js"></script>
<script src="/fontpage/js/small.function.js"></script>
<script src="/fontpage/js/modal.js"></script>
<script type="text/javascript">
        $(function () {
            $(".returntop").click(function () {
                $('body,html').animate({ scrollTop: 0 }, 1000);
            });
            var height = document.getElementById("container").offsetHeight;
            if (height <= 568) {
                $("#minHeight").addClass('minHeight');
                $(".returntop").hide();
            }
        });
    </script>
<div class="container" id="container">
        <div class="wrapper">
            <div id="minHeight" class="minHeight">
                <div class="common-wrapper mbNone">
                    <div class="common-body">


                        <input type="hidden" value="{{isset($info->id)?$info->id:''}}" name="id" id="aid">
                        <div class="step4 border-1px">
                            <div class="s-item bdb-1px">
                                <div class="sitem-r">

                                        <input type="text" id="Address" name="address" value="{{isset($info->address)?$info->address:''}}" class="w8" placeholder="请输入详细地址">




                                    <b class="jf-close" style="right:20px;display:none;"></b>
                                </div>
                            </div>
                        </div>



                        <div class="step4 border-1px">
                            <div class="s-item bdb-1px">
                                <div class="sitem-r">

                                        <input type="text" id="UserName" name="name" value="{{isset($info->name)?$info->name:''}}" class="w8" placeholder="请输入姓名">


                                    <b class="jf-close" style="right:20px;display:none;"></b>
                                </div>
                            </div>
                        </div>

                        <div class="step4 border-1px">
                            <div class="s-item bdb-1px">
                                <div class="sitem-r">

                                        <input type="text" id="Tel" name="mobile" class="w8" value="{{isset($info->mobile)?$info->mobile:''}}" placeholder="请输入手机号">




                                    <b class="jf-close" style="right:20px;display:none;"></b>
                                </div>
                            </div>
                        </div>
                        <div class="step4 border-1px">
                            <div class="s-item bdb-1px">
                                <div class="sitem-r">

                                        <input type="text" id="ZipCode" name="code" class="w8" value="{{isset($info->code)?$info->code:''}}" placeholder="请输入6位数邮编">




                                    <b class="jf-close" style="right:20px;display:none;"></b>
                                </div>
                            </div>
                        </div>

                            <div class="f_choose
                            @if(isset($info->is_default) && $info->is_default==1)
                            f_choose_selected
                            @endif
                            "
                             @if(isset($info->is_default) && $info->is_default==1)
                              data-checked="true"
                            @endif
                            >
                                <b></b>
                                <label class="sh_mr">{{translate("设置为默认地址")}}</label>
                            </div>

                        <div class="f_btn
                        @if(empty($info))
                        gary
                        @endif

                        "
                        @if(!empty($info))
                        data-disable="false"
                        @else
                        data-disable="true"
                        @endif
                        >
                            {{translate("确定")}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {

            $(".jf-close").click(function () {
                $("#Address").val("");
                $(".f_btn").addClass("gary");
                $(".f_btn").attr("data-disable", "true");
                $(".jf-close").css("display", "none");
            })
            $('#Address').bind('input propertychange', function () {
                var val = $(this).val();
                if (val == "" || val.length < 2 || val.length > 100) {
                    $(".f_btn").addClass("gary");
                    $(".f_btn").attr("data-disable", "true");
                    $(".jf-close").css("display", "none");
                }
                else {
                    $(".f_btn").removeClass("gary");
                    $(".f_btn").attr("data-disable", "false");
                    $(".jf-close").css("display", "block");
                }
            });
        });

        function go_index() {
            window.location.href = '/Home/Index/';
        }
        function containSpecial(s) {
            var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(#)($)(\%)(\^)(\&)(\*)(\()(\))(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);
            return (containSpecial.test(s));
        }
        var click = 0;
        var isDefault = 1;//默认地址
        $('.f_btn').click(function () {
            //是否默认
            var checked = $(".f_choose").attr("data-checked");
            var isMain=0;
            if(checked=="true")
            {
                isMain=1;
            }
            else
            {
                isMain=0;
            }

            if ($(".f_btn").attr("data-disable") == "true") {
                return false;
            }

            if (click == 1) {
                return false;
            }
            click = 1;

            var Id = $("#aid").val();

            var Address = $('#Address').val();
            if (Address == "" || Address == null) {
                $.prompt(data.Msg, {
                    buttons: { "{{translate('确定')}}": true }
                });
                return;
            }
            var UserName = $('#UserName').val();
            if (UserName == "" || UserName == null) {
                alert('{{translate("姓名不能为空")}}', {
                    buttons: { "{{translate('确定')}}": true }
                });
                return;
            }
            if (containSpecial(UserName)) {
                $.modal({ title: "{{translate('提示信息')}}", content: "{{translate('姓名不能包含特殊字符')}}", top: '20%', bottom: [{ name: "{{translate('确定')}}", click: '$.close()', classs: 'btn-ios-default' }] });
                click = 0;
                return;
            }

            var Tel = $('#Tel').val();
            if (Tel == "" || Tel == null) {
                alert('{{translate("手机号码不能为空")}}', {
                    buttons: { '{{translate("确定")}}': true }
                });
                return;
            }
            if (containSpecial(Tel)) {
                $.modal({ title: "{{translate('提示信息')}}", content: "{{translate('手机号码不能包含特殊字符')}}", top: '20%', bottom: [{ name: "{{translate('确定')}}", click: '$.close()', classs: 'btn-ios-default' }] });
                click = 0;
                return;
            }

            var Phone = $('#Phone').val();
            var ZipCode = $('#ZipCode').val();
            if (ZipCode == "" || ZipCode == null) {
                alert('{{translate("邮编不能为空")}}', {
                    buttons: { '{{translate("确定")}}': true }
                });
                return;
            }
            if (containSpecial(ZipCode)) {
                $.modal({ title: "{{translate('提示信息')}}", content: "{{translate('邮编不能包含特殊字符')}}", top: '20%', bottom: [{ name: "{{translate('确定')}}", click: '$.close()', classs: 'btn-ios-default' }] });
                click = 0;
                return;
            }

            ajaxurl('',{ id:Id , address: Address,mobile: Tel, name: UserName, code: ZipCode , is_default: isMain },function(res){
    			layer.msg(res.msg)
    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
            var type = getQueryString('type');
            if(!type) type = 0;
            var url = '{{JpUrl("/user/toAddress")}}'
            if(url.indexOf('?') > 0){
              url = url+'&type='+type
            }else{
              url = url+'?type='+type
            }
    				window.location.href = url//页面刷新
    			},2000);
    		})

        });

        $(".f_choose").click(function () {
            var checked = $(this).attr("data-checked");
            if (checked == "true") {//取消默认
                $(this).attr("data-checked", "false");
                $(this).removeClass("f_choose_selected");
                isDefault = 1;
            }
            else
            {
                $(this).attr("data-checked", "true");
                $(this).addClass("f_choose_selected");
                isDefault = 0;
            }

        })


    </script>
@endsection
@section('footer')
     @include('common.footer')
@stop
